/*
 * plconfig.h
 *
 *  Created on: May 3, 2017
 *      Author: yuanjianen
 */

#ifndef _PLCONFIG_H_
#define _PLCONFIG_H_

#include "typedef.h"

/* for bootloader */
#define SOFT_BOOTSOFT					(0)
#define SOFT_APPSOFT					(1)
/*The MCU has only app soft, with no bootloader*/
#define SOFT_APPSOFT_ONLY				(2)
#define PLCFG_SOFTWARE_TYPE				(SOFT_APPSOFT)

/*******************************************************************
 ********       Module En/disable module                    *******
 *******************************************************************/
#define PLCFG_CCP_ENABLED                   (1U)
#define PLCFG_DTC_ENABLED                   (1U)

/*Configure the frequency of external clock*/
/*jzy:actually useless*/
#define M_freedom_board					(FALSE)
#if(M_freedom_board == TRUE)
#define PLCONFIG_EXTERNAL_OSC_CLOCK 	(EXTERNAL_CLOCK_8M)
#else
#define PLCONFIG_EXTERNAL_OSC_CLOCK 	(EXTERNAL_CLOCK_16M)
#endif

#define M_debug_version					(TRUE)

#if 1
#define PLCFG_SPI_TASK_TIME				(2U)
#define PLCFG_INPUT_SAMPLE_TASK_TIME 	(2U)
#define PLCFG_AD_SAMPLE_TASK_TIME		(2U)
#define PLCFG_CAN_TRX_TASK_TIME			(1U)
#define PLCFG_APL_TASK_TIME				(5U)
#define PLCFG_NM_TASK_TIME				(5U)
#define PLCFG_OBDM_TASK_TIME			(10U)
#define PLCFG_EEP_TASK_TIME				(2U)
#define PLCFG_SLEEP_TASK_TIME			(10u)
#define PLCFG_DESC_TASK_TIME			(1U)
#define PLCFG_ISOTP_TASK_TIME			(1U)
#define PLCFG_CCP_DAQ_PROC_TASK_TIME    (PLCFG_CAN_TRX_TASK_TIME)
#else
#define PLCFG_INPUT_SAMPLE_TASK_TIME 	(ALARM_CYCLE_OsAlarmIo)
#define PLCFG_AD_SAMPLE_TASK_TIME		(ALARM_CYCLE_OsAlarmAd)
#define PLCFG_CAN_TRX_TASK_TIME			(ALARM_CYCLE_OsAlarmCanTrx)
#define PLCFG_APL_TASK_TIME				(ALARM_CYCLE_OsAlarmHHTApplication)
#define PLCFG_OBDM_TASK_TIME			(10U)
#define PLCFG_EEP_TASK_TIME				(2U)
#define PLCFG_SLEEP_TASK_TIME			(10u)
#define PLCFG_DESC_TASK_TIME			(ALARM_CYCLE_OsAlarmUdsDesc)
#define PLCFG_ISOTP_TASK_TIME			(ALARM_CYCLE_OsAlarmUdsIsotp)
#endif

#define M_make_uw(hi,lo)				(	((uint16)(hi)<< 8)| \
											((uint16)(lo)<< 0)  )

#define M_make_ud(hh,hl,lh,ll)			(	((uint32)(hh)<<24)| \
											((uint32)(hl)<<16)| \
											((uint32)(lh)<< 8)| \
											((uint32)(ll)<< 0)  )

#if(M_debug_version == TRUE)
#define M_assert(x)						while(!(x)){}
#else
#define M_assert(x)
#endif


/*******************************************************************
 ********  Flash / Ram / EEPRom / Register range definition  *******
 *******************************************************************/
#define EEPROM_ADDRESS_BEGIN                (0xF1000UL)
#define EEPROM_ADDRESS_END                  (0xF2FFFUL)
#define EEPROM_SIZE                         (EEPROM_ADDRESS_END - EEPROM_ADDRESS_BEGIN + 1U)

#if 0
#define EEPROM_APL_ADDRESS_BEGIN            (0xF1000UL)
#define EEPROM_APL_ADDRESS_END              (0xF2FFFUL)

#define EEPROM_CAL_ADDRESS_BEGIN            (0xFF208000UL)
#define EEPROM_CAL_ADDRESS_END              (0xFF20FFFFUL)
#endif

#define RAM_ADDRESS_BEGIN               	(0xFD700UL)
#define RAM_ADDRESS_END                 	(0xFFEDFUL)
#define RAM_SIZE                        	(PRI_RAM_ADDRESS_BEGIN - PRI_RAM_ADDRESS_END + 1U)

#define ROM_ADDRESS_SUBMCU_IMAGE            (0x1F800UL)	/*jzy: apl last packet of data,fill with arbitrary data ,512 byte align*/

#define ROM_ADDRESS_BEGIN                   (0x03000uL)
#define ROM_ADDRESS_END                     (0x1FFFFUL)
#define ROM_SIZE                            ((ROM_ADDRESS_END - ROM_ADDRESS_BEGIN + 1U))
//jzy: Allocate free RAM
#define FlASH_DRV_ADDRESS_BEGIN             (0xFFD00)
#define FlASH_DRV_ADDRESS_END               (0xFFDFF)
#define FlASH_DRV_SIZE                      (0x100UL)

#endif /* _PLCONFIG_H_ */
